package com.ruoyi.web.controller.system.api.cc;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.api.domain.ReportInfo;
import com.ruoyi.system.api.domain.ServiceLogVo;
import com.ruoyi.system.api.mapper.PlanDetailsMapper;
import com.ruoyi.system.api.mapper.ReportInfoMapper;
import com.ruoyi.system.api.service.IPlanDetailsService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.alibaba.fastjson.JSONObject;
import com.ruoyi.framework.interceptor.Authentication;
import com.ruoyi.system.api.ResponseWithData;
import com.ruoyi.system.api.domain.MyPlanCount;
import com.ruoyi.system.api.service.CcService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.system.api.domain.ServiceNotice;
import com.ruoyi.system.api.service.IServiceNoticeService;
import com.ruoyi.common.core.controller.BaseController;

/**
 * 服务派单主 (数据来源于CC端主动调用)Controller
 *
 * @author shihx
 * @date 2020-03-02
 */
@Api(tags = "服务派单主表 (数据来源于CC端主动调用)")
@Controller
@RequestMapping("/api/cc/notice")
public class ServiceNoticeController extends BaseController {

    @Autowired
    private IServiceNoticeService serviceNoticeService;
    @Autowired
    private CcService ccService;

    @Autowired
    private IPlanDetailsService planDetailsService;

    @Autowired
    private PlanDetailsMapper planDetailsMapper;
    @Autowired
    private ReportInfoMapper reportInfoMapper;
    private static final Logger log = LoggerFactory.getLogger(ServiceNoticeController.class);

    /**
     * 获取TL下所有未关闭(待指派)的服务通知接口
     *
     * @param TeamleaderId
     * @methodName: getServiceNotice
     * @description: TODO
     * @return: com.ruoyi.system.api.ResponseWithData<?>
     * @author: shihx
     * @date: 2020/3/2 15:03
     **/
    @GetMapping("/getServiceNotice")
    @ResponseBody
    @Authentication(tokenRequired = true, signRequired = true)
    @ApiOperation(value = "获取TL下所有未关闭(待指派)的服务通知接口", httpMethod = "GET", notes = "获取TL下所有未关闭(待指派)的服务通知接口")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "TL主键ID", name = "TeamleaderId", required = true, defaultValue = "10009", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "APP状态（1：待派单、2：服务中、3：已关闭）", name = "AppState", required = true, defaultValue = "2", dataType = "Long", paramType = "query"),
    })
    @ApiResponses({
            @ApiResponse(code = 500, message = "code 为 500 系统异常"),
            @ApiResponse(code = 200, message = "code 为 200 成功", response = ServiceNotice.class)
    })
    public ResponseWithData<?> getServiceNotice(
            @RequestParam(value = "TeamleaderId", required = true) String TeamleaderId,
            @RequestParam(value = "AppState", required = true) Long AppState
    ) {
        try {
            ServiceNotice serviceNotice = new ServiceNotice();
            serviceNotice.setTeamleaderId(TeamleaderId);
            serviceNotice.setAppState(AppState);
            serviceNotice.setAppIsAccept("0");
            serviceNotice.setDelFlag("0");
            List<ServiceNotice> list = serviceNoticeService.selectServiceNoticeList(serviceNotice);
            return new ResponseWithData<>().success(list).msg("查询成功").code(200);
        } catch (Exception e) {
            log.error("程序异常", e.getMessage());
            return new ResponseWithData().error().msg("系统异常").code(500);
        }
    }

    /**
     * 获取工程师下待接受、进行中服务单的数量接口
     *
     * @param EnginnerId
     * @methodName: getMyPlanCount
     * @description: TODO
     * @return: com.ruoyi.system.api.ResponseWithData<?>
     * @author: shihx
     * @date: 2020/3/2 15:25
     **/
    @GetMapping("/getMyPlanCount")
    @ResponseBody
    @Authentication(tokenRequired = true, signRequired = true)
    @ApiOperation(value = "获取工程师下待接受、进行中服务单的数量接口", httpMethod = "GET", notes = "获取工程师下待接受、进行中服务单的数量接口")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "工程师主键ID", name = "EnginnerId", required = true, defaultValue = "10009", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "客户名称", name = "customerName", required = false, defaultValue = "10009", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "服务类型", name = "serviceType", required = false, defaultValue = "10009", dataType = "String", paramType = "query"),
    })
    @ApiResponses({
            @ApiResponse(code = 500, message = "code 为 500 系统异常"),
            @ApiResponse(code = 200, message = "code 为 200 成功", response = MyPlanCount.class)
    })
    public ResponseWithData<?> getMyPlanCount(
            @RequestParam(value = "EnginnerId", required = true) String EnginnerId,
            @RequestParam(value = "customerName", required = false) String customerName,
            @RequestParam(value = "serviceType", required = false) String serviceType

    ) {
        try {
            return serviceNoticeService.getMyPlanCount(EnginnerId, customerName, serviceType);
        } catch (Exception e) {
            log.error("程序异常", e.getMessage());
            return new ResponseWithData().error().msg("系统异常").code(500);
        }
    }

    /**
     * 获取工程师TEAM下待接受、进行中服务单的数量接口
     *
     * @param EnginnerId
     * @methodName: getMyTeamPlanCount
     * @description: TODO
     * @return: com.ruoyi.system.api.ResponseWithData<?>
     * @author: bairuihua
     * @date: 2020/5/22 15:25
     **/
    @GetMapping("/getMyTeamPlanCount")
    @ResponseBody
    @Authentication(tokenRequired = true, signRequired = true)
    @ApiOperation(value = "获取工程师TEAM下待接受、进行中服务单的数量接口", httpMethod = "GET", notes = "获取工程师下待接受、进行中服务单的数量接口")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "工程师主键ID", name = "EnginnerId", required = true, defaultValue = "10009", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "客户名称", name = "customerName", required = false, defaultValue = "001", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "服务类型", name = "serviceType", required = false, defaultValue = "10009", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "工程师姓名", name = "enginnerName", required = false, defaultValue = "10009", dataType = "String", paramType = "query")
    })
    @ApiResponses({
            @ApiResponse(code = 500, message = "code 为 500 系统异常"),
            @ApiResponse(code = 200, message = "code 为 200 成功", response = HashMap.class)
    })
    public ResponseWithData<?> getMyTeamPlanCount(
            @RequestParam(value = "EnginnerId", required = true) String EnginnerId,
            @RequestParam(value = "customerName", required = false) String customerName,
            @RequestParam(value = "serviceType", required = false) String serviceType,
            @RequestParam(value = "enginnerName", required = false) String enginnerName

    ) {
        try {
            return serviceNoticeService.getMyTeamPlanCount(EnginnerId, customerName, serviceType, enginnerName);
        } catch (Exception e) {
            log.error("程序异常", e.getMessage());
            return new ResponseWithData().error().msg("系统异常").code(500);
        }
    }

    /**
     * 获取工程师下待接受、进行中服务单列表的接口
     *
     * @param EnginnerId
     * @methodName: getMyServiceNotice
     * @description: TODO
     * @return: com.ruoyi.system.api.ResponseWithData<?>
     * @author: shihx
     * @date: 2020/3/2 16:37
     **/
    @GetMapping("/getMyServiceNotice")
    @ResponseBody
    @Authentication(tokenRequired = true, signRequired = true)
    @ApiOperation(value = "获取工程师下待接受、进行中服务单列表的接口", httpMethod = "GET", notes = "获取工程师下待接受、进行中服务单列表的接口")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "工程师主键ID", name = "EnginnerId", required = true, defaultValue = "10009", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "状态（0：待接受、1：进行中）", name = "state", required = true, defaultValue = "1", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "客户名称", name = "customerName", required = false, defaultValue = "10009", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "服务类型", name = "serviceType", required = false, defaultValue = "10009", dataType = "String", paramType = "query"),
    })
    @ApiResponses({
            @ApiResponse(code = 500, message = "code 为 500 系统异常"),
            @ApiResponse(code = 200, message = "code 为 200 成功", response = ServiceNotice.class)
    })
    public ResponseWithData<?> getMyServiceNotice(
            @RequestParam(value = "EnginnerId", required = true) String EnginnerId,
            @RequestParam(value = "state", required = true) String state,
            @RequestParam(value = "customerName", required = false) String customerName,
            @RequestParam(value = "serviceType", required = false) String serviceType
    ) {
        try {
            return serviceNoticeService.getMyServiceNotice(EnginnerId, state, customerName, serviceType);
        } catch (Exception e) {
            log.error("程序异常", e.getMessage());
            return new ResponseWithData().error().msg("系统异常").code(500);
        }
    }

    /**
     * 获取工程师下待接受、进行中服务单详情的接口
     *
     * @param ServiceNoticeId
     * @param EnginnerId
     * @methodName: getMyServiceNoticeDetail
     * @description: TODO
     * @return: com.ruoyi.system.api.ResponseWithData<?>
     * @author: shihx
     * @date: 2020/3/3 13:05
     **/
    @GetMapping("/getMyServiceNoticeDetail")
    @ResponseBody
    @Authentication(tokenRequired = true, signRequired = true)
    @ApiOperation(value = "获取工程师下待接受、进行中服务单详情的接口", httpMethod = "GET", notes = "获取工程师下待接受、进行中服务单详情的接口")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "服务单主键ID", name = "ServiceNoticeId", required = true, defaultValue = "1", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "工程师ID", name = "EnginnerId", required = true, defaultValue = "1", dataType = "String", paramType = "query"),
    })
    @ApiResponses({
            @ApiResponse(code = 500, message = "code 为 500 系统异常"),
            @ApiResponse(code = 200, message = "code 为 200 成功", response = ServiceNotice.class)
    })
    public ResponseWithData<?> getMyServiceNoticeDetail(
            @RequestParam(value = "ServiceNoticeId", required = true) String ServiceNoticeId,
            @RequestParam(value = "EnginnerId", required = true) String EnginnerId
    ) {
        try {
            return serviceNoticeService.getMyServiceNoticeDetail(ServiceNoticeId, EnginnerId);
        } catch (Exception e) {
            log.error("程序异常", e.getMessage());
            return new ResponseWithData().error().msg("系统异常").code(500);
        }
    }

    /**
     * 2.3获取TL列表接口
     *
     * @param TeamleaderId
     * @methodName: getTeamleaderList
     * @description: TODO
     * @return: com.ruoyi.system.api.ResponseWithData<?>
     * @author: shihx
     * @date: 2020/3/3 15:23
     **/
    @GetMapping("/getTeamleaderList")
    @ResponseBody
    @Authentication(tokenRequired = true, signRequired = true)
    @ApiOperation(value = "2.3获取TL列表接口", httpMethod = "GET", notes = "2.3获取TL列表接口")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "TL主键ID", name = "TeamleaderId", required = true, defaultValue = "10009", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "TL姓名（搜索条件）", name = "TeamleaderName", required = false, defaultValue = "张三", dataType = "String", paramType = "query"),
    })
    @ApiResponses({
            @ApiResponse(code = 500, message = "code 为 500 系统异常"),
            @ApiResponse(code = 200, message = "code 为 200 成功")
    })
    public ResponseWithData<?> getTeamleaderList(
            @RequestParam(value = "TeamleaderId", required = true) String TeamleaderId,
            @RequestParam(value = "TeamleaderName", required = false) String TeamleaderName
    ) {
        try {
            return serviceNoticeService.getTeamleaderList(TeamleaderId, TeamleaderName);
        } catch (Exception e) {
            log.error("程序异常", e.getMessage());
            return new ResponseWithData().error().msg("系统异常").code(500);
        }
    }

    /**
     * 2.4TL转派其他TL接口
     *
     * @param TeamleaderId
     * @param serviceNo
     * @param NewTeamleaderId
     * @methodName: TransferTL
     * @description: TODO
     * @return: com.ruoyi.system.api.ResponseWithData<?>
     * @author: shihx
     * @date: 2020/3/3 16:39
     **/
    @Log(title = "2.4TL转派其他TL接口", businessType = BusinessType.UPDATE)
    @GetMapping("/TransferTL")
    @ResponseBody
    @Authentication(tokenRequired = true, signRequired = true)
    @ApiOperation(value = "2.4TL转派其他TL接口", httpMethod = "GET", notes = "2.4TL转派其他TL接口")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "当前TL主键ID", name = "TeamleaderId", required = true, defaultValue = "10009", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "服务号", name = "serviceNo", required = true, defaultValue = "001", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "要转派的新的TL主键ID", name = "NewTeamleaderId", required = true, defaultValue = "001", dataType = "String", paramType = "query"),
    })
    @ApiResponses({
            @ApiResponse(code = 500, message = "code 为 500 系统异常"),
            @ApiResponse(code = 200, message = "code 为 200 成功")
    })
    public ResponseWithData<?> TransferTL(
            @RequestParam(value = "TeamleaderId", required = true) String TeamleaderId,
            @RequestParam(value = "serviceNo", required = true) String serviceNo,
            @RequestParam(value = "NewTeamleaderId", required = true) String NewTeamleaderId
    ) {
        try {
            return serviceNoticeService.TransferTL(TeamleaderId, serviceNo, NewTeamleaderId);
        } catch (Exception e) {
            log.error("程序异常", e.getMessage());
            return new ResponseWithData().error().msg("系统异常").code(500);
        }
    }

    /**
     * TL确定派单接口
     *
     * @param ServiceNoticeId
     * @param serviceNo
     * @param EnginnerIds
     * @param EnginnerNames
     * @methodName: ConfirmationDispatch
     * @description: TODO
     * @return: com.ruoyi.system.api.ResponseWithData<?>
     * @author: shihx
     * @date: 2020/3/5 13:39
     **/
    @Log(title = "TL确定派单接口", businessType = BusinessType.UPDATE)
    @GetMapping("/ConfirmationDispatch")
    @ResponseBody
    @Authentication(tokenRequired = true, signRequired = true)
    @ApiOperation(value = "TL确定派单接口", httpMethod = "GET", notes = "TL确定派单接口")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "服务单主键ID", name = "ServiceNoticeId", required = true, defaultValue = "10009", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "服务号", name = "serviceNo", required = true, defaultValue = "001", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "选择要派单工程师的id(多人用逗号分割)", name = "EnginnerIds", required = true, defaultValue = "001", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "选择要派单工程师的姓名(多人用逗号分割)", name = "EnginnerNames", required = true, defaultValue = "001", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "指派人)", name = "assignId", required = true, defaultValue = "001", dataType = "String", paramType = "query")

    })
    @ApiResponses({
            @ApiResponse(code = 500, message = "code 为 500 系统异常"),
            @ApiResponse(code = 200, message = "code 为 200 成功")
    })
    public ResponseWithData<?> ConfirmationDispatch(
            @RequestParam(value = "ServiceNoticeId", required = true) String ServiceNoticeId,
            @RequestParam(value = "serviceNo", required = true) String serviceNo,
            @RequestParam(value = "EnginnerIds", required = true) String EnginnerIds,
            @RequestParam(value = "EnginnerNames", required = true) String EnginnerNames,
            @RequestParam(value = "assignId", required = true) String assignId
    ) {
        try {
            return serviceNoticeService.ConfirmationDispatch(ServiceNoticeId, serviceNo, EnginnerIds, EnginnerNames, assignId);
        } catch (Exception e) {
            e.printStackTrace();
            log.error("程序异常", e.getMessage());
            return new ResponseWithData().error().msg("系统异常").code(500);
        }
    }

    /**
     * 接受服务单、签到服务单、签离服务单、填写工作日志 查询关联服务单接口
     *
     * @param ServiceNoticeId
     * @param EnginnerId
     * @param signInTime
     * @param signIn
     * @param fillInLog
     * @param state
     * @methodName: AssociatedCustomers
     * @description: TODO
     * @return: com.ruoyi.system.api.ResponseWithData<?>
     * @author: shihx
     * @date: 2020/3/11 9:54
     **/
    @GetMapping("/AssociatedCustomers")
    @ResponseBody
    @Authentication(tokenRequired = true, signRequired = true)
    @ApiOperation(value = "接受服务单、签到服务单、签离服务单、填写工作日志 查询关联服务单接口", httpMethod = "GET", notes = "接受服务单、签到服务单、签离服务单、填写工作日志 查询关联服务单接口")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "服务单主键ID", name = "ServiceNoticeId", required = true, defaultValue = "10009", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "已接受服务单工程师ID", name = "EnginnerId", required = true, defaultValue = "10009", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "签到时间（用于签离查询）", name = "signInTime", required = true, defaultValue = "", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "签到状态（用于日志查询）", name = "signIn", required = true, defaultValue = "", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "是否填写日志（用于日志查询）", name = "fillInLog", required = true, defaultValue = "", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "服务端状态（用于接受，签到查询）", name = "state", required = true, defaultValue = "", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "自己子表的主键ID", name = "planId", required = true, defaultValue = "", dataType = "String", paramType = "query"),
    })
    @ApiResponses({
            @ApiResponse(code = 500, message = "code 为 500 系统异常"),
            @ApiResponse(code = 200, message = "code 为 200 成功")
    })
    public ResponseWithData<?> AssociatedCustomers(
            @RequestParam(value = "ServiceNoticeId", required = true) String ServiceNoticeId,
            @RequestParam(value = "EnginnerId", required = true) String EnginnerId,
            @RequestParam(value = "signInTime", required = false) String signInTime,
            @RequestParam(value = "signIn", required = false) String signIn,
            @RequestParam(value = "fillInLog", required = false) String fillInLog,
            @RequestParam(value = "state", required = false) String state,
            @RequestParam(value = "planId", required = false) String planId
    ) {
        try {
            return serviceNoticeService.AssociatedCustomers(ServiceNoticeId, EnginnerId, signInTime, signIn, fillInLog, state, planId);
        } catch (Exception e) {
            e.printStackTrace();
            log.error("程序异常", e.getMessage());
            return new ResponseWithData().error().msg("系统异常").code(500);
        }
    }


    /**
     * 查询关联服务单接口
     *
     * @param ServiceNoticeId
     * @param EnginnerId
     * @param signInTime
     * @param signIn
     * @param fillInLog
     * @param state
     * @methodName: AssociatedCustomers
     * @description: TODO
     * @return: com.ruoyi.system.api.ResponseWithData<?>
     * @author: shihx
     * @date: 2020/3/11 9:54
     **/
    @GetMapping("/associatedCustomerSrelevance")
    @ResponseBody
    @Authentication(tokenRequired = true, signRequired = true)
    @ApiOperation(value = "接受服务单、签到服务单、签离服务单、填写工作日志 查询关联服务单接口", httpMethod = "GET", notes = "接受服务单、签到服务单、签离服务单、填写工作日志 查询关联服务单接口")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "服务单主键ID", name = "ServiceNoticeId", required = true, defaultValue = "10009", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "已接受服务单工程师ID", name = "EnginnerId", required = true, defaultValue = "10009", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "签到时间（用于签离查询）", name = "signInTime", required = true, defaultValue = "", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "签到状态（用于日志查询）", name = "signIn", required = true, defaultValue = "", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "是否填写日志（用于日志查询）", name = "fillInLog", required = true, defaultValue = "", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "服务端状态（用于接受，签到查询）", name = "state", required = true, defaultValue = "", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "自己子表的主键ID", name = "planId", required = true, defaultValue = "", dataType = "String", paramType = "query"),
    })
    @ApiResponses({
            @ApiResponse(code = 500, message = "code 为 500 系统异常"),
            @ApiResponse(code = 200, message = "code 为 200 成功")
    })
    public ResponseWithData<?> associatedCustomerSrelevance(
            @RequestParam(value = "ServiceNoticeId", required = true) String ServiceNoticeId,
            @RequestParam(value = "EnginnerId", required = true) String EnginnerId,
            @RequestParam(value = "signInTime", required = false) String signInTime,
            @RequestParam(value = "signIn", required = false) String signIn,
            @RequestParam(value = "fillInLog", required = false) String fillInLog,
            @RequestParam(value = "state", required = false) String state,
            @RequestParam(value = "planId", required = false) String planId
    ) {
        try {

           return serviceNoticeService.AssociatedCustomersByBatch(ServiceNoticeId, EnginnerId, signInTime, signIn, fillInLog, state, planId);
        } catch (Exception e) {
            e.printStackTrace();
            log.error("程序异常", e.getMessage());
            return new ResponseWithData().error().msg("系统异常").code(500);
        }
    }


    /**
     * 查询关联服务单接口是否有提交报告
     *
     * @param ServiceNoticeId
     * @param EnginnerId
     * @param signInTime
     * @param state
     * @methodName: AssociatedCustomers
     * @description: TODO
     * @return: com.ruoyi.system.api.ResponseWithData<?>
     * @author: shihx
     * @date: 2020/3/11 9:54
     **/
    @GetMapping("/associatedCustomerSrelevanceByReport")
    @ResponseBody
    @Authentication(tokenRequired = true, signRequired = true)
    @ApiOperation(value = "接受服务单、签到服务单、签离服务单、填写工作日志 查询关联服务单接口", httpMethod = "GET", notes = "接受服务单、签到服务单、签离服务单、填写工作日志 查询关联服务单接口")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "服务单主键ID", name = "ServiceNoticeId", required = true, defaultValue = "10009", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "已接受服务单工程师ID", name = "EnginnerId", required = true, defaultValue = "10009", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "签到时间（用于签离查询）", name = "signInTime", required = true, defaultValue = "", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "服务端状态（用于接受，签到查询）", name = "state", required = true, defaultValue = "", dataType = "String", paramType = "query"),

    })
    @ApiResponses({
            @ApiResponse(code = 500, message = "code 为 500 系统异常"),
            @ApiResponse(code = 200, message = "code 为 200 成功")
    })
    public ResponseWithData<?> associatedCustomerSrelevanceByReport(
            @RequestParam(value = "ServiceNoticeId", required = true) String ServiceNoticeId,
            @RequestParam(value = "EnginnerId", required = true) String EnginnerId,
            @RequestParam(value = "signInTime", required = false) String signInTime,
            @RequestParam(value = "state", required = false) String state
    ) {
        try {

            return serviceNoticeService.associatedCustomersByReport(ServiceNoticeId, EnginnerId,signInTime,state);
        } catch (Exception e) {
            e.printStackTrace();
            log.error("程序异常", e.getMessage());
            return new ResponseWithData().error().msg("系统异常").code(500);
        }
    }

    /**
     * 获取工程师下各状态服务单列表的接口
     *
     * @param EnginnerId
     * @methodName: getServiceNoticeList
     * @description: TODO
     * @return: com.ruoyi.system.api.ResponseWithData<?>
     * @author: sjy
     * @date: 2020年3月9日14:31:17
     **/
    @GetMapping("/getServiceNoticeList")
    @ResponseBody
    @Authentication(tokenRequired = true, signRequired = true)
    @ApiOperation(value = "获取工程师下各状态服务单列表的接口", httpMethod = "GET", notes = "获取工程师下各状态服务单列表的接口")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "工程师主键ID", name = "EnginnerId", required = true, defaultValue = "10009", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "服务单主键ID", name = "ServiceNoticeId", required = false, defaultValue = "10009", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "状态（0待接受，1已接受，2已签到，3已签离，4已完成,5自动签离，6已拒绝）", name = "state", required = true, defaultValue = "1", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "客户名称", name = "customerName", required = false, defaultValue = "10009", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "服务类型", name = "serviceType", required = false, defaultValue = "10009", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "仪器序列号", name = "instrumentSerialNumber", required = false, defaultValue = "10009", dataType = "String", paramType = "query"),
    })
    @ApiResponses({
            @ApiResponse(code = 500, message = "code 为 500 系统异常"),
            @ApiResponse(code = 200, message = "code 为 200 成功", response = ServiceNotice.class)
    })
    public ResponseWithData<?> getServiceNoticeList(
            @RequestParam(value = "EnginnerId", required = true) String EnginnerId,
            @RequestParam(value = "state", required = true) String state,
            @RequestParam(value = "ServiceNoticeId", required = false) String ServiceNoticeId,
            @RequestParam(value = "customerName", required = false) String customerName,
            @RequestParam(value = "serviceType", required = false) String serviceType,
            @RequestParam(value = "instrumentSerialNumber", required = false) String instrumentSerialNumber
    ) {
        try {
            return serviceNoticeService.getServiceNoticeList(EnginnerId, Long.parseLong(state), ServiceNoticeId, customerName, serviceType, instrumentSerialNumber);
        } catch (Exception e) {
            log.error("程序异常", e.getMessage());
            return new ResponseWithData().error().msg("系统异常").code(500);
        }
    }


    /**
     * 获取工程师下各状态服务单列表的接口
     *
     * @param EnginnerId
     * @methodName: getClosedNoticeList
     * @description: TODO
     * @return: com.ruoyi.system.api.ResponseWithData<?>
     * @author: sjy
     * @date: 2020年3月9日14:31:17
     **/
    @GetMapping("/getClosedNoticeList")
    @ResponseBody
    @Authentication(tokenRequired = true, signRequired = true)
    @ApiOperation(value = "获取工程师下已关闭服务单列表的接口", httpMethod = "GET", notes = "获取工程师下各状态服务单列表的接口")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "工程师主键ID", name = "EnginnerId", required = true, defaultValue = "10009", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "状态（1待派单 2服务中 3已关闭）", name = "AppState", required = true, defaultValue = "1", dataType = "Long", paramType = "query"),
            @ApiImplicitParam(value = "服务号", name = "serviceNo", required = false, defaultValue = "001", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "客户名称", name = "customerName", required = false, defaultValue = "10009", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "服务类型", name = "serviceType", required = false, defaultValue = "10009", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "仪器序列号", name = "instrumentSerialNumber", required = false, defaultValue = "10009", dataType = "String", paramType = "query"),
    })
    @ApiResponses({
            @ApiResponse(code = 500, message = "code 为 500 系统异常"),
            @ApiResponse(code = 200, message = "code 为 200 成功", response = ServiceNotice.class)
    })
    public ResponseWithData<?> getClosedNoticeList(
            @RequestParam(value = "EnginnerId", required = true) String EnginnerId,
            @RequestParam(value = "AppState", required = true) Long AppState,
            @RequestParam(value = "serviceNo", required = false) String serviceNo,
            @RequestParam(value = "customerName", required = false) String customerName,
            @RequestParam(value = "serviceType", required = false) String serviceType,
            @RequestParam(value = "instrumentSerialNumber", required = false) String instrumentSerialNumber
    ) {
        try {
            return serviceNoticeService.getClosedNoticeList(EnginnerId, AppState, serviceNo, customerName, serviceType, instrumentSerialNumber);
        } catch (Exception e) {
            log.error("程序异常", e.getMessage());
            return new ResponseWithData().error().msg("系统异常").code(500);
        }
    }


    /**
     * 获取TL或工程师下待指派和服务中的服务通知接口
     *
     * @param TeamleaderId
     * @methodName: getServiceNotice
     * @description: TODO
     * @return: com.ruoyi.system.api.ResponseWithData<?>
     * @author: sjy
     * @date: 2020年3月9日17:27:19
     **/
    @GetMapping("/getTeamServiceNotice")
    @ResponseBody
    @Authentication(tokenRequired = true, signRequired = true)
    @ApiOperation(value = "获取TL或工程师下待指派和服务中的服务通知接口", httpMethod = "GET", notes = "获取TL或工程师下待指派和服务中的服务通知接口")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "TL主键ID", name = "TeamleaderId", required = false, defaultValue = "10009", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "服务号", name = "serviceNo", required = false, defaultValue = "001", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "客户名称", name = "customerName", required = false, defaultValue = "001", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "工程师ID", name = "enginnerId", required = false, defaultValue = "001", dataType = "Long", paramType = "query"),
            @ApiImplicitParam(value = "服务类型", name = "serviceType", required = false, defaultValue = "10009", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "服务单状态", name = "appState", required = false, defaultValue = "10009", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "计划状态", name = "state", required = false, defaultValue = "10009", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "仪器序列号", name = "instrumentSerialNumber", required = false, defaultValue = "10009", dataType = "String", paramType = "query"),
    })
    @ApiResponses({
            @ApiResponse(code = 500, message = "code 为 500 系统异常"),
            @ApiResponse(code = 200, message = "code 为 200 成功", response = ServiceNotice.class)
    })
    public ResponseWithData<?> getTeamServiceNotice(@RequestParam(value = "TeamleaderId", required = false) String TeamleaderId,
                                                    @RequestParam(value = "serviceNo", required = false) String serviceNo,
                                                    @RequestParam(value = "customerName", required = false) String customerName,
                                                    @RequestParam(value = "enginnerId", required = false) Long enginnerId,
                                                    @RequestParam(value = "serviceType", required = false) String serviceType,
                                                    @RequestParam(value = "appState", required = false) String appState,
                                                    @RequestParam(value = "state", required = false) String state,
                                                    @RequestParam(value = "instrumentSerialNumber", required = false) String instrumentSerialNumber
    ) {
        try {
            ServiceNotice serviceNotice = new ServiceNotice();
            serviceNotice.setTeamleaderId(TeamleaderId);
            serviceNotice.setServiceNo(serviceNo);
            serviceNotice.setCustomerName(customerName);
            serviceNotice.setEnginnerId(enginnerId);
            serviceNotice.setServiceType(serviceType);
            serviceNotice.setSubServiceType(instrumentSerialNumber);
            String as = "1,2";
            if ("2".equals(appState)) {
                as = appState;
            }
            serviceNotice.setServiceLevel(as);
            serviceNotice.setServiceStatus(state);
            List<ServiceNotice> list = serviceNoticeService.getTeamServiceNotice(serviceNotice);
            return new ResponseWithData<>().success(list).msg("查询成功").code(200);
        } catch (Exception e) {
            log.error("程序异常", e.getMessage());
            return new ResponseWithData().error().msg("系统异常").code(500);
        }
    }

    /**
     * 获取待派工服务单详情的接口
     *
     * @param ServiceNoticeId
     * @methodName: getDaiZhiPaiNoticeDetail
     * @description: TODO
     * @return: com.ruoyi.system.api.ResponseWithData<?>
     * @author: shihx
     * @date: 2020/3/18 16:36
     **/
    @GetMapping("/getDaiZhiPaiNoticeDetail")
    @ResponseBody
    @Authentication(tokenRequired = true, signRequired = true)
    @ApiOperation(value = "获取待派工服务单详情的接口", httpMethod = "GET", notes = "获取待派工服务单详情的接口")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "服务单主键ID", name = "ServiceNoticeId", required = true, defaultValue = "1", dataType = "String", paramType = "query"),
    })
    @ApiResponses({
            @ApiResponse(code = 500, message = "code 为 500 系统异常"),
            @ApiResponse(code = 200, message = "code 为 200 成功", response = ServiceNotice.class)
    })
    public ResponseWithData<?> getDaiZhiPaiNoticeDetail(
            @RequestParam(value = "ServiceNoticeId", required = true) Long ServiceNoticeId
    ) {
        try {
            ServiceNotice serviceNotice = serviceNoticeService.selectServiceNoticeById(ServiceNoticeId);
            return new ResponseWithData<>().success(serviceNotice).msg("查询成功").code(200);
        } catch (Exception e) {
            log.error("程序异常", e.getMessage());
            return new ResponseWithData().error().msg("系统异常").code(500);
        }
    }


    /**
     * 获取FSE下维护报告列表（未关闭的服务）
     *
     * @param enginnerId
     * @methodName: getServiceNotice
     * @description: TODO
     * @return: com.ruoyi.system.api.ResponseWithData<?>
     * @author: sjy
     * @date: 2020年3月22日13:10:08
     **/
    @GetMapping("/getFseReportNotice")
    @ResponseBody
    @Authentication(tokenRequired = true, signRequired = true)
    @ApiOperation(value = "获取FSE下维护报告列表（未关闭的服务）", httpMethod = "GET", notes = "获取FSE下维护报告列表（未关闭的服务）")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "工程师ID", name = "enginnerId", required = true, defaultValue = "10009", dataType = "Long", paramType = "query"),
            @ApiImplicitParam(value = "服务号", name = "serviceNo", required = false, defaultValue = "001", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "客户名称", name = "customerName", required = false, defaultValue = "001", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "服务类型", name = "serviceType", required = false, defaultValue = "001", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "仪器序列号", name = "instSn", required = false, defaultValue = "001", dataType = "String", paramType = "query"),
    })
    @ApiResponses({
            @ApiResponse(code = 500, message = "code 为 500 系统异常"),
            @ApiResponse(code = 200, message = "code 为 200 成功", response = ServiceNotice.class)
    })
    public ResponseWithData<?> getFseReportNotice(@RequestParam(value = "enginnerId", required = true) Long enginnerId,
                                                  @RequestParam(value = "serviceNo", required = false) String serviceNo,
                                                  @RequestParam(value = "customerName", required = false) String customerName,
                                                  @RequestParam(value = "serviceType", required = false) String serviceType,
                                                  @RequestParam(value = "instSn", required = false) String instSn) {
        try {
            ServiceNotice serviceNotice = new ServiceNotice();
            serviceNotice.setEnginnerId(enginnerId);
            serviceNotice.setServiceNo(serviceNo);
            serviceNotice.setCustomerName(customerName);
            serviceNotice.setServiceType(serviceType);
            serviceNotice.setInstSn(instSn);
        //    List<ServiceNotice> list = serviceNoticeService.getFseReportNotice(serviceNotice);
            List<ServiceNotice> list = serviceNoticeService.getFseReportNoticeAll(serviceNotice);

            return new ResponseWithData<>().success(list).msg("查询成功").code(200);
        } catch (Exception e) {
            log.error("程序异常", e.getMessage());
            return new ResponseWithData().error().msg("系统异常").code(500);
        }
    }


    /**
     * 获取FSE下维护报告列表有 error  和 hot 报告的服务列表
     *
     * @param enginnerId
     * @methodName: getServiceNotice
     * @description: TODO
     * @return: com.ruoyi.system.api.ResponseWithData<?>
     * @author: sjy
     * @date: 2020年3月22日13:10:08
     **/
    @GetMapping("/getFseReportNoticeByErrorOrHot")
    @ResponseBody
    @Authentication(tokenRequired = true, signRequired = true)
    @ApiOperation(value = "获取FSE下维护报告列表（未关闭的服务）", httpMethod = "GET", notes = "获取FSE下维护报告列表（未关闭的服务）")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "工程师ID", name = "enginnerId", required = true, defaultValue = "10009", dataType = "Long", paramType = "query"),
            @ApiImplicitParam(value = "服务号", name = "serviceNo", required = false, defaultValue = "001", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "客户名称", name = "customerName", required = false, defaultValue = "001", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "服务类型", name = "serviceType", required = false, defaultValue = "001", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "仪器序列号", name = "instSn", required = false, defaultValue = "001", dataType = "String", paramType = "query"),
    })
    @ApiResponses({
            @ApiResponse(code = 500, message = "code 为 500 系统异常"),
            @ApiResponse(code = 200, message = "code 为 200 成功", response = ServiceNotice.class)
    })
    public ResponseWithData<?> getFseReportNoticeByErrorOrHot(@RequestParam(value = "enginnerId", required = true) Long enginnerId,
                                                              @RequestParam(value = "serviceNo", required = false) String serviceNo,
                                                              @RequestParam(value = "customerName", required = false) String customerName,
                                                              @RequestParam(value = "serviceType", required = false) String serviceType,
                                                              @RequestParam(value = "instSn", required = false) String instSn,
                                                              @RequestParam(value = "status", required = false) String status) {
        try {
            ServiceNotice serviceNotice = new ServiceNotice();
            serviceNotice.setEnginnerId(enginnerId);
            serviceNotice.setServiceNo(serviceNo);
            serviceNotice.setCustomerName(customerName);
            serviceNotice.setServiceType(serviceType);
            serviceNotice.setInstSn(instSn);
            serviceNotice.setStatus(status);
            List<ServiceNotice> list = serviceNoticeService.getFseReportNoticeSubmitByErrorOrHot(serviceNotice);
            return new ResponseWithData<>().success(list).msg("查询成功").code(200);
        } catch (Exception e) {
            log.error("程序异常", e.getMessage());
            return new ResponseWithData().error().msg("系统异常").code(500);
        }
    }

    /**
     * 关闭服务通知
     *
     * @param enginnerId
     * @methodName: getServiceNotice
     * @description: TODO
     * @return: com.ruoyi.system.api.ResponseWithData<?>
     * @author: sjy
     * @date: 2020年3月22日13:10:08
     **/
    @Log(title = "关闭服务通知", businessType = BusinessType.UPDATE)
    @GetMapping("/closeNotice")
    @ResponseBody
    @Authentication(tokenRequired = true, signRequired = true)
    @ApiOperation(value = "关闭服务通知", httpMethod = "GET", notes = "关闭服务通知")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "工程师ID", name = "enginnerId", required = true, defaultValue = "10009", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "服务号", name = "serviceNo", required = true, defaultValue = "001", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "服务单主键ID", name = "serviceNoticeId", required = false, defaultValue = "1", dataType = "String", paramType = "query"),
    })
    @ApiResponses({
            @ApiResponse(code = 500, message = "code 为 500 系统异常"),
            @ApiResponse(code = 200, message = "code 为 200 成功", response = ServiceNotice.class)
    })
    public ResponseWithData<?> closeNotice(@RequestParam(value = "enginnerId", required = true) String enginnerId,
                                           @RequestParam(value = "serviceNo", required = true) String serviceNo,
                                           @RequestParam(value = "ServiceNoticeId", required = false) Long ServiceNoticeId) {
        try {

            List<ReportInfo> plist = serviceNoticeService.getUnSubmitReport(serviceNo);
            if (!ObjectUtils.isEmpty(plist)) {
                return new ResponseWithData<>().error().msg("有未提交的报告，不能关闭服务").code(200);
            }
            JSONObject jsonObject = ccService.closeNotice(enginnerId, serviceNo, ServiceNoticeId);
            return new ResponseWithData<>().success(jsonObject).msg("查询成功").code(200);
        } catch (Exception e) {
            log.error("程序异常", e.getMessage());
            return new ResponseWithData().error().msg("系统异常").code(500);
        }
    }


    /**
     * 关闭Error服务通知
     *
     * @param enginnerId
     * @methodName: getServiceNotice
     * @description: TODO
     * @return: com.ruoyi.system.api.ResponseWithData<?>
     * @author: sjy
     * @date: 2020年3月22日13:10:08
     **/
    @Log(title = "关闭Error服务通知", businessType = BusinessType.UPDATE)
    @GetMapping("/errorReportCloseNotice")
    @ResponseBody
    @Authentication(tokenRequired = true, signRequired = true)
    @ApiOperation(value = "关闭Error服务通知", httpMethod = "GET", notes = "关闭Error服务通知")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "工程师ID", name = "enginnerId", required = true, defaultValue = "10009", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "服务号", name = "serviceNo", required = true, defaultValue = "001", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "服务报告", name = "reportGuid", required = false, defaultValue = "1", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "类型", name = "reportType", required = false, defaultValue = "1", dataType = "String", paramType = "query"),
    })
    @ApiResponses({
            @ApiResponse(code = 500, message = "code 为 500 系统异常"),
            @ApiResponse(code = 200, message = "code 为 200 成功", response = ServiceNotice.class)
    })
    public ResponseWithData<?> errorReportCloseNotice(@RequestParam(value = "enginnerId", required = true) String enginnerId,
                                                      @RequestParam(value = "serviceNo", required = true) String serviceNo,
                                                      @RequestParam(value = "reportGuid", required = true) String reportGuid,
                                                      @RequestParam(value = "reportType", required = true) String reportType) {
        try {
            if (StringUtils.isEmpty(reportGuid)) {
                return new ResponseWithData().error().msg("reportGuid为空").code(201);
            }
            String id = reportInfoMapper.selectByreportNo(reportGuid).get(0).getId().toString();
            if (StringUtils.isEmpty(id)) {
                return new ResponseWithData().error().msg("根据reportGuid不能找到reportInfo").code(202);
            }
            JSONObject jsonObject = ccService.errorReportCloseNotice(id, enginnerId, serviceNo, reportGuid, reportType);
            return new ResponseWithData<>().success(jsonObject).msg("请求成功").code(200);
        } catch (Exception e) {
            log.error("程序异常", e.getMessage());
            return new ResponseWithData().error().msg("系统异常").code(500);
        }
    }


    /**
     * 关闭服务通知同时自动签离
     *
     * @param enginnerId
     * @methodName: getServiceNotice
     * @description: TODO
     * @return: com.ruoyi.system.api.ResponseWithData<?>
     * @author: sjy
     * @date: 2020年3月22日13:10:08
     **/
    @Log(title = "关闭服务通知同时自动签离", businessType = BusinessType.UPDATE)
    @GetMapping("/closeNoticeAndSignoff")
    @ResponseBody
    @Authentication(tokenRequired = true, signRequired = true)
    @ApiOperation(value = "关闭服务通知同时自动签离", httpMethod = "GET", notes = "关闭服务通知同时自动签离")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "工程师ID", name = "enginnerId", required = true, defaultValue = "10009", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "服务号", name = "serviceNo", required = true, defaultValue = "001", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "服务单主键ID", name = "serviceNoticeId", required = false, defaultValue = "1", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "客户名称", name = "customerName", required = true, defaultValue = "中国", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "签到时间", name = "signInTime", required = true, defaultValue = "2020-111-12 12:12:12", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "经度", name = "longitude", required = true, defaultValue = "125.222", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "纬度", name = "latitude", required = true, defaultValue = "43.2222", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "状态", name = "state", required = true, defaultValue = "4", dataType = "String", paramType = "query"),
    })
    @ApiResponses({
            @ApiResponse(code = 500, message = "code 为 500 系统异常"),
            @ApiResponse(code = 200, message = "code 为 200 成功", response = ServiceNotice.class)
    })
    public ResponseWithData<?> closeNoticeAndSignoff(
            @RequestParam(value = "enginnerId", required = true) String enginnerId,
            @RequestParam(value = "serviceNo", required = true) String serviceNo,
            @RequestParam(value = "serviceNoticeId", required = true) Long serviceNoticeId,
            @RequestParam(value = "customerName", required = true) String customerName,
            @RequestParam(value = "signInTime", required = false) String signInTime,
            @RequestParam(value = "longitude", required = true) String longitude,
            @RequestParam(value = "latitude", required = true) String latitude,
            @RequestParam(value = "state", required = true) String state
    ) {
        try {
            List<ReportInfo> plist = serviceNoticeService.getUnSubmitReport(serviceNo);
            if (!ObjectUtils.isEmpty(plist)) {
                return new ResponseWithData<>().error().msg("有未提交的报告，不能关闭服务").code(200);
            }
            JSONObject jsonObject = ccService.closeNotice(enginnerId, serviceNo, serviceNoticeId);
            String code = jsonObject.get("code").toString();
            if ("200".equals(jsonObject.get("code").toString())) {
                int noticeNum = planDetailsMapper.selectNoClosedNum(serviceNo, enginnerId);
                if (noticeNum > 0) {
                    if(signInTime!=null){
                        planDetailsService.fseSignOff(serviceNoticeId.toString(), serviceNo, enginnerId, customerName, signInTime, longitude, latitude, state);
                    }

                }
            }
            return new ResponseWithData<>().success(jsonObject).msg("关闭成功").code(200);
        } catch (Exception e) {
            log.error("程序异常", e.getMessage());
            return new ResponseWithData().error().msg("系统异常").code(500);
        }
    }

    /**
     * 查询服务详情(只是想通过serviceNo取到省、市、上门服务地址)
     *
     * @param serviceNo
     * @methodName: getDetailsByServiceNo
     * @description: TODO
     * @return: com.ruoyi.system.api.ResponseWithData<?>
     * @author: wlf
     * @date: 2020/4/5 10:38
     **/
    @GetMapping("/getDetailsByServiceNo")
    @ResponseBody
    @Authentication(tokenRequired = true, signRequired = true)
    @ApiOperation(value = "查询服务详情", httpMethod = "GET", notes = "查询服务详情")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "服务单号", name = "serviceNo", required = true, defaultValue = "10009", dataType = "String", paramType = "query"),
    })
    @ApiResponses({
            @ApiResponse(code = 500, message = "code 为 500 系统异常"),
            @ApiResponse(code = 200, message = "code 为 200 成功")
    })
    public ResponseWithData<?> getDetailsByServiceNo(
            @RequestParam(value = "serviceNo", required = true) String serviceNo) {
        try {
            ServiceNotice serviceNotice = new ServiceNotice();
            serviceNotice.setServiceNo(serviceNo);
            List<ServiceNotice> list = serviceNoticeService.selectServiceNoticeList(serviceNotice);
            return new ResponseWithData<>().success(list.get(0)).msg("查询成功").code(200);
        } catch (Exception e) {
            log.error("程序异常", e.getMessage());
            return new ResponseWithData().error().msg("系统异常").code(500);
        }
    }

    /**
     * 查看服务通知详情
     *
     * @param serviceNo
     * @param serviceNoticeId
     * @param planId
     * @param enginnerId
     * @return com.ruoyi.system.api.ResponseWithData
     * @author yzg
     * @date 2020/4/14 4:54 下午
     */
    @GetMapping("/getServiceNoticeDetailsAndReportCount")
    @ResponseBody
    @Authentication(tokenRequired = true, signRequired = true)
    @ApiOperation(value = "查看服务通知详情", httpMethod = "GET", notes = "查看服务通知详情")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "服务单号", name = "serviceNo", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "服务单id", name = "serviceNoticeId", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "计划id", name = "planId,", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "用户id", name = "enginnerId", required = true, dataType = "String", paramType = "query"),
    })
    @ApiResponses({
            @ApiResponse(code = 500, message = "code 为 500 系统异常"),
            @ApiResponse(code = 200, message = "code 为 200 成功")
    })
    public ResponseWithData getServiceNoticeDetailsAndReportCount(@RequestParam("serviceNo") String serviceNo, @RequestParam("serviceNoticeId") Long serviceNoticeId, @RequestParam("planId") Long planId, @RequestParam("enginnerId") Long enginnerId) {
        try {
            return serviceNoticeService.getServiceNoticeDetailsAndReportCount(serviceNo, serviceNoticeId, planId, enginnerId);
        } catch (Exception e) {
            e.printStackTrace();
            log.error("程序异常", e.getMessage());
            return new ResponseWithData().error().msg("系统异常").code(500);
        }
    }

    /**
     * 查询CC端服务通知（处理）
     *
     * @param enginnerId
     * @return com.ruoyi.system.api.ResponseWithData
     * @author yzg
     * @date 2020/4/15 2:08 下午
     */
    @GetMapping("/getCCServiceNoticeList")
    @ResponseBody
    @Authentication(tokenRequired = true, signRequired = true)
    @ApiOperation(value = "查询CC端服务通知（处理）", httpMethod = "GET", notes = "查询CC端服务通知（处理）")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "用户id", name = "enginnerId", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "用户id", name = "serviceNo", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "custName", name = "custName", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "仪器序列号", name = "instrumentSerialNumber", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "开始时间", name = "startTime", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "结束时间", name = "endTime", required = false, dataType = "String", paramType = "query")
    })
    @ApiResponses({
            @ApiResponse(code = 500, message = "code 为 500 系统异常"),
            @ApiResponse(code = 200, message = "code 为 200 成功")
    })
    public ResponseWithData getCCServiceNoticeList(@RequestParam(value="enginnerId" ,required=true) Long enginnerId,
                                                   @RequestParam(value="serviceNo" ,required=false) String serviceNo,
                                                   @RequestParam(value="custName" ,required=false ) String custName,
                                                   @RequestParam(value="instrumentSerialNumber",required=false) String instrumentSerialNumber,
                                                   @RequestParam(value="startTime",required=false) String startTime,
                                                   @RequestParam(value="endTime",required=false) String endTime
                                                   ) {
        try {
            return serviceNoticeService.getCCServiceNoticeList(enginnerId,serviceNo,custName,instrumentSerialNumber,startTime,endTime);
        } catch (Exception e) {
            log.error("程序异常", e.getMessage());
            return new ResponseWithData().error().msg("系统异常").code(500);
        }
    }

    /**
     * 待指派有搜索条件的查询
     *
     * @param enginnerId
     * @param state
     * @param customerName
     * @param serviceType
     * @methodName: getAssignServiceNotice
     * @description: TODO
     * @return: com.ruoyi.system.api.ResponseWithData<?>
     * @author: shihx
     * @date: 2020-04-16 13:51
     **/
    @GetMapping("/getAssignServiceNotice")
    @ResponseBody
    @Authentication(tokenRequired = true, signRequired = true)
    @ApiOperation(value = "待指派有搜索条件的查询", httpMethod = "GET", notes = "待指派有搜索条件的查询")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "工程师主键ID", name = "enginnerId", required = true, defaultValue = "10009", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "状态（0：待接受、1：进行中）", name = "state", required = true, defaultValue = "1", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "客户名称", name = "customerName", required = false, defaultValue = "10009", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "服务类型", name = "serviceType", required = false, defaultValue = "10009", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "仪器序列号", name = "instrumentSerialNumber", required = false, defaultValue = "10009", dataType = "String", paramType = "query"),
    })
    @ApiResponses({
            @ApiResponse(code = 500, message = "code 为 500 系统异常"),
            @ApiResponse(code = 200, message = "code 为 200 成功", response = ServiceNotice.class)
    })
    public ResponseWithData<?> getAssignServiceNotice(
            @RequestParam(value = "enginnerId", required = true) String enginnerId,
            @RequestParam(value = "state", required = true) String state,
            @RequestParam(value = "customerName", required = false) String customerName,
            @RequestParam(value = "serviceType", required = false) String serviceType,
            @RequestParam(value = "instrumentSerialNumber", required = false) String instrumentSerialNumber
    ) {
        try {
            return serviceNoticeService.getAssignServiceNotice(enginnerId, state, customerName, serviceType, instrumentSerialNumber);
        } catch (Exception e) {
            log.error("程序异常", e.getMessage());
            return new ResponseWithData().error().msg("系统异常").code(500);
        }
    }

    @GetMapping("/getTeamServiceNotices")
    @ResponseBody
    @Authentication(tokenRequired = true, signRequired = true)
    @ApiOperation(value = "查询团队服务通知接口", httpMethod = "GET", notes = "查询团队服务通知接口")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "TL主键ID", name = "TeamleaderId", required = false, defaultValue = "10009", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "客户名称", name = "customerName", required = false, defaultValue = "001", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "服务类型", name = "serviceType", required = false, defaultValue = "10009", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "服务单状态", name = "appState", required = false, defaultValue = "10009", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "工程师姓名", name = "enginnerName", required = false, defaultValue = "10009", dataType = "String", paramType = "query"),
    })
    @ApiResponses({
            @ApiResponse(code = 500, message = "code 为 500 系统异常"),
            @ApiResponse(code = 200, message = "code 为 200 成功", response = ServiceNotice.class)
    })
    public ResponseWithData<?> getTeamServiceNotices(@RequestParam(value = "TeamleaderId", required = false) String TeamleaderId,
                                                     @RequestParam(value = "customerName", required = false) String customerName,
                                                     @RequestParam(value = "serviceType", required = false) String serviceType,
                                                     @RequestParam(value = "appState", required = false) String appState,
                                                     @RequestParam(value = "enginnerName", required = false) String enginnerName
    ) {
        try {
            ServiceNotice serviceNotice = new ServiceNotice();
            serviceNotice.setTeamleaderId(TeamleaderId);
            serviceNotice.setCustomerName(customerName);
            serviceNotice.setServiceType(serviceType);
            serviceNotice.setServiceStatus(enginnerName);
            serviceNotice.setProvince(appState);
            List<ServiceNotice> list = serviceNoticeService.getTeamServiceNotices(serviceNotice);
            return new ResponseWithData<>().success(list).msg("查询成功").code(200);
        } catch (Exception e) {
            log.error("程序异常", e.getMessage());
            return new ResponseWithData().error().msg("系统异常").code(500);
        }
    }


    @GetMapping("/getTeamServiceNoticesByTL")
    @ResponseBody
    @Authentication(tokenRequired = true, signRequired = true)
    @ApiOperation(value = "查询团队服务通知接口", httpMethod = "GET", notes = "查询团队服务通知接口")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "TL主键ID", name = "TeamleaderId", required = false, defaultValue = "10009", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "客户名称", name = "customerName", required = false, defaultValue = "001", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "服务类型", name = "serviceType", required = false, defaultValue = "10009", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "服务单状态", name = "appState", required = false, defaultValue = "10009", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "工程师姓名", name = "enginnerName", required = false, defaultValue = "10009", dataType = "String", paramType = "query"),
    })
    @ApiResponses({
            @ApiResponse(code = 500, message = "code 为 500 系统异常"),
            @ApiResponse(code = 200, message = "code 为 200 成功", response = ServiceNotice.class)
    })
    public ResponseWithData<?> getTeamServiceNoticesByTL(@RequestParam(value = "TeamleaderId", required = false) String TeamleaderId,
                                                     @RequestParam(value = "customerName", required = false) String customerName,
                                                     @RequestParam(value = "serviceType", required = false) String serviceType,
                                                     @RequestParam(value = "appState", required = false) String appState,
                                                     @RequestParam(value = "enginnerName", required = false) String enginnerName
    ) {
        try {
            ServiceNotice serviceNotice = new ServiceNotice();
            serviceNotice.setTeamleaderId(TeamleaderId);
            serviceNotice.setCustomerName(customerName);
            serviceNotice.setServiceType(serviceType);
            serviceNotice.setServiceStatus(enginnerName);
            serviceNotice.setProvince(appState);
            List<ServiceNotice> list = serviceNoticeService.getTeamServiceNoticesBytl(serviceNotice);
            return new ResponseWithData<>().success(list).msg("查询成功").code(200);
        } catch (Exception e) {
            log.error("程序异常", e.getMessage());
            return new ResponseWithData().error().msg("系统异常").code(500);
        }
    }

    @GetMapping("/getTeamSpares")
    @ResponseBody
    @Authentication(tokenRequired = true, signRequired = true)
    @ApiOperation(value = "查询团队Fse备件接口", httpMethod = "GET", notes = "查询团队Fse备件接口")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "fseId", name = "fseId", required = true, defaultValue = "10009", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "partNo", name = "partNo", required = true, defaultValue = "1234567", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "status", name = "status", required = true, defaultValue = "0", dataType = "String", paramType = "query")

    })
    @ApiResponses({
            @ApiResponse(code = 500, message = "code 为 500 系统异常"),
            @ApiResponse(code = 200, message = "code 为 200 成功", response = ServiceNotice.class)
    })
    public ResponseWithData<?> getTeamSpares(@RequestParam(value = "fseId", required = true) String fseId,
                                             @RequestParam(value = "partNo", required = true) String partNo,
                                             @RequestParam(value = "status", required = true) String status
    ) {
        try {
            return ccService.getTeamSpares(fseId,partNo,status);
        } catch (Exception e) {
            log.error("程序异常", e.getMessage());
            return new ResponseWithData().error().msg("系统异常").code(500);
        }
    }

    @PostMapping("/getServiceNoticeListByNotLog")
    @ResponseBody
    @Authentication(tokenRequired = true, signRequired = true)
    @ApiOperation(value = "查询没有服务日志的通知", httpMethod = "POST", notes = "查询没有服务日志的通知")
    @ApiResponses({
            @ApiResponse(code = 500, message = "code 为 500 系统异常"),
            @ApiResponse(code = 200, message = "code 为 200 成功", response = ServiceNotice.class)
    })
    public ResponseWithData<?> getServiceNoticeListByNotLog(@RequestBody Map<String, Object> serviceNotice) {
        try {

            List<Map<String, Object>> list = serviceNoticeService.selectServiceNoticeListByNotLog(serviceNotice);
            return new ResponseWithData<>().success(list).msg("查询成功").code(200);
        } catch (Exception e) {
            e.printStackTrace();
            log.error("程序异常", e.getMessage());
            return new ResponseWithData().error().msg("系统异常").code(500);
        }
    }
    /**
     * 客户签名列表页
     *
     * @return com.ruoyi.system.api.ResponseWithData<?>
     * @author sjy
     * @date 2020年3月21日13:10:52
     */
    @GetMapping("/getAllCustomerSignListModify")
    @ResponseBody
    @Authentication(tokenRequired = true, signRequired = true)
    @ApiOperation(value = "客户签名列表页", httpMethod = "GET", notes = "客户签名列表页")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "工程师ID", name = "enginnerId", required = true, defaultValue = "10009", dataType = "Long", paramType = "query"),
            @ApiImplicitParam(value = "客户名称", name = "customerName", required = false, defaultValue = "001", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "服务类型", name = "serviceType", required = false, defaultValue = "001", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "仪器序列号", name = "instSn", required = false, defaultValue = "001", dataType = "String", paramType = "query"),
    })
    @ApiResponses({
            @ApiResponse(code = 500, message = "code 为 500 系统异常"),
            @ApiResponse(code = 200, message = "code 为 200 成功")
    })
    public ResponseWithData<?> getAllCustomerSignListModify(@RequestParam(value = "enginnerId", required = true) Long enginnerId,
                                                            @RequestParam(value = "customerName", required = false) String customerName,
                                                            @RequestParam(value = "serviceType", required = false) String serviceType,
                                                            @RequestParam(value = "instSn", required = false) String instSn) {
        try {
            Map map = new HashMap();
            map.put("enginnerId",enginnerId);
            map.put("customerName",customerName);
            map.put("serviceType",serviceType);
            map.put("instSn",instSn);
            List<ServiceNotice> list = serviceNoticeService.getAllCustomerSignListModify(map);
            return new ResponseWithData<>().success(list).msg("查询成功").code(200);
        } catch (Exception e) {
            log.error("程序异常", e.getMessage());
            return new ResponseWithData().error().msg("系统异常").code(500);
        }
    }

}
